package com.cn.wanxi.controller;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.entity.UserEntity;
import com.cn.wanxi.service.IUserService;
import com.cn.wanxi.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
@RequestMapping("/back/user")
public class UserController {
    @Autowired
    private IUserService iUserService;
    @RequestMapping("/del")
    public void del(UserEntity userEntity, HttpServletResponse resp) throws IOException {
        //        3.调用service
        String result = iUserService.del(userEntity.getId());
        //        将得到的数据返回给前端
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("result", result);
        resp.getWriter().println(jsonObject);
    }
    @RequestMapping("/findById")
    public UserEntity findById(UserEntity userEntity, HttpServletResponse resp) throws IOException {
         return iUserService.findById(userEntity.getId());
    }

}
